﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.JoinParty.BLL;
using FineUI;
using System.Data;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.Core.Util;

namespace JoinParty.admin.FlowStep
{
    public partial class JoinPartyInspectionAdd : PageBase
    {
        public string ID
        {
            get
            {
                return GetQueryIntValue("id");
            }
        }
        
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "";
            }
        }

        #endregion
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                LoadData();
            }
        }

        private void BindData()
        {
        }
        private void LoadData(string IsSave = "")
        {

            var example = DB.PartyJoinLinkExamples.Find(this.CurrentStandID);
            if (example != null)
            {
                PartyJoinApplycation app = ProcesUtil.GetApplycation(example.AppllicationID);
                this.hdAppID.Value = app.AppllicationID;
                this.hdAppLoginID.Value = app.LoginID;
                this.hdCurrentStandID.Value = this.CurrentStandID;
                this.hdUserName.Value = app.UserName;
                this.dtOptionTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
        }



        private void SaveData(bool isClose, bool Submit = false)
        {
            bool bResult = false;
            PartyJoinReviewOption rep = new PartyJoinReviewOption();
            rep.LoginID = this.hdAppLoginID.Value;
            rep.LoginName = this.hdUserName.Value;
            rep.StandID = this.CurrentStandID;
            rep.OptionTime = Convert.ToDateTime(this.dtOptionTime.Text);
            rep.ID = StringHelper.NewID;
            rep.CreateTime = DateTime.Now;
            DB.PartyJoinReviewOptions.Add(rep);
            bResult = DB.SaveChanges() > 0;

            if (bResult)
            {
                if (Submit)
                    Alert.Show("保存成功", String.Empty, ActiveWindow.GetHideReference());
                else
                    Alert.Show("提交成功", String.Empty, ActiveWindow.GetHideReference());
            }
        }

        #endregion

        #region
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            this.SaveData(true);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SaveData(true, true);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}